﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace QuanLyKhachHang.Data
{
    class TTWeb
    {
        public string MaWeb, MaKhachHang, TenWeb, DonViTK, MaNhanVien;
        public DateTime ThoiGianTK, ThoiHanTM;
        public TTWeb() { }
        public TTWeb(string MaWeb, string MaKhachHang, string TenWeb, string DonViTK, DateTime ThoiGianTK, DateTime ThoiHanTM, string MaNhanVien)
        {
            this.MaWeb = MaWeb;
            this.MaKhachHang = MaKhachHang;
            this.TenWeb = TenWeb;
            this.DonViTK = DonViTK;
            this.ThoiGianTK = ThoiGianTK;
            this.ThoiHanTM = ThoiHanTM;
            this.MaNhanVien = MaNhanVien;
        }
    }

    class NVWeb
    {
        public static DataTable ChonTatCa()
        { 
            return Connect.cnSQL.ExecQuery("Select * from Web");
        }
        public static DataTable ChonTatCa(string MaKhachHang)
        { 
            return Connect.cnSQL.ExecQuery("SELECT     Web.*, NhanVien.TenNhanVien FROM Web LEFT OUTER JOIN  NhanVien ON Web.MaNhanVien = NhanVien.MaNhanVien and Web.MaKhachHang='"+ MaKhachHang+"'");
        }
        public static bool Them(TTWeb Web)
        {
            Connect.cnSQL.ExecNonQuery("Insert into Web values('" + Web.MaWeb + "','" + Web.MaKhachHang + "','" + Web.TenWeb + "','" + Web.DonViTK + "',convert(datetime, '" + Web.ThoiGianTK + "', 103),convert(datetime, '" + Web.ThoiHanTM + "', 103),'" + Web.MaNhanVien + "')");
            return (!Connect.Tools.CoLoi);
        }
        public static bool Sua(TTWeb Web)
        {
            Connect.cnSQL.ExecNonQuery("Update Web Set MaKhachHang='" + Web.MaKhachHang + "', TenWeb='" + Web.TenWeb + "', DonViTK='" + Web.DonViTK + "',ThoiGianTK=convert(datetime, '" + Web.ThoiGianTK + "', 103), ThoiHanTM=convert(datetime, '" + Web.ThoiHanTM + "', 103), MaNhanVien='" + Web.MaNhanVien + "'  where MaWeb='" + Web.MaWeb + "'");
            return (!Connect.Tools.CoLoi);
        }
        public static bool Xoa(string Ma)
        {
            Connect.cnSQL.ExecNonQuery("Delete Web where MaWeb ='" + Ma + "'");
            return (!Connect.Tools.CoLoi);
        }
    }
}
